package com.wgts.wgts.mvp.view.activity.search;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.BaseLoadMoreAdapter;
import com.wgts.wgts.netmodle.resp.SearchStoreResultEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

public class SearchResultShopAdapter extends BaseLoadMoreAdapter<SearchResultShopAdapter.SearchResultShopViewHolder> {

    private Context context;

    private List<SearchStoreResultEntity.StoreList> srcData;

    private OnClickListener onClickListener;

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public SearchResultShopAdapter(Context context, List<SearchStoreResultEntity.StoreList> srcData) {
        super(context);
        this.context = context;
        this.srcData = srcData;
    }

    @Override
    public void onBindBodyViewHolder(@NonNull SearchResultShopViewHolder viewHolder, final int i) {
        MoHuGlide.getInstance().glideImgsFormList(viewHolder.imgShop, srcData.get(i).shopAvator, context);
        viewHolder.tvShop.setText(srcData.get(i).shopName);
        if (srcData.get(i).fansCount == 0){
            viewHolder.tvShopGoods.setText("0个粉丝");
        }else {
            viewHolder.tvShopGoods.setText(srcData.get(i).fansCount + "个粉丝");
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener != null){
                    onClickListener.onClick(v, i);
                }
            }
        });
    }

    @NonNull
    @Override
    public SearchResultShopViewHolder onCreateBodyViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new SearchResultShopViewHolder(LayoutInflater.from(context).inflate(R.layout.search_result_shop_view_holder, viewGroup, false));
    }

    @Override
    public int getBodyItemCount() {
        return srcData.size();
    }

    @Override
    public int getBodyItemViewType(int position) {
        return 0;
    }

    public class SearchResultShopViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_shop)
        CircleImageView imgShop;
        @BindView(R.id.linear_into_shop)
        LinearLayout linearIntoShop;
        @BindView(R.id.tv_shop)
        TextView tvShop;
        @BindView(R.id.tv_shop_goods)
        TextView tvShopGoods;

        View itemView;
        public SearchResultShopViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

    public interface OnClickListener{
        void onClick(View view, int i);
    }

}
